#include <iostream>
#include <future>
#include <thread>
#include <chrono>
using namespace std::chrono_literals;
int main()
{
    // 来自 packaged_task 的 future
    std::promise<int> p;
    std::future<int>  f3 = p.get_future();
    std::thread(
        [&p]
        {
            std::cout << "1...\n" << std::endl;
            std::this_thread::sleep_for(1s);
            p.set_value_at_thread_exit(9);
            std::cout << "2...\n" << std::endl;
        })
        .detach();

    std::cout << "Waiting...\n" << std::endl;
    std::this_thread::sleep_for(1s);
    f3.wait();
    std::cout << "Done!\nResults are: " << f3.get() << '\n';
}